//package com.example.stock.service;
//
//import cn.hutool.json.JSONUtil;
//import com.example.stock.entity.Stock;
//import com.example.stock.util.HolidayUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.PostConstruct;
//import java.text.ParseException;
//import java.time.LocalDate;
//import java.time.LocalDateTime;
//import java.time.format.DateTimeFormatter;
//import java.util.List;
//import java.util.Objects;
//
//@Service
//@Slf4j
//public class DengXiaHeiClass {
//
//    @Autowired
//    private IStockService stockService;
//
//
//    @PostConstruct
//    public void calc() throws ParseException {
//        String calcDate = "2024-12-18";
//        for(int j=0;j<30;j++) {
//            List<Stock> stocks = stockService.listByCalcTimeAndCalcType( calcDate, 3);
//            log.info("计算日期：{}",calcDate);
//            for (int i = 0; i < stocks.size(); i++) {
//                Stock stock = stocks.get(i);
//                int count = 1;
//                String nextGzr = calcDate;
//                //是涨停
//                if (stock.getChangePercent() < 11 && Objects.equals(stock.getPriceNow(), stock.getHighLimit()) && !stock.getName().contains("ST")) {
//                    while (count <= 6) {
//                        //获取 3天 5天 7天内的低于一半量比的
//                        nextGzr = getNextGzr(LocalDate.parse(nextGzr, DateTimeFormatter.ofPattern("yyyy-MM-dd")).atStartOfDay());
//                        Stock stock2 = stockService.getByCodeAndCalcTimeAndCalcType(stock.getCode(), nextGzr, 3);
//                        if(stock2 != null && Objects.equals(stock2.getPriceNow(), stock2.getLowLimit())){
//                            break;
//                        }
//                        if(stock2 != null && stock2.getPriceNow() <= stock.getPriceMin()){
//                            break;
//                        }
//                        if ( stock2 != null  && stock2.getChangePercent()>1.5 && (!Objects.equals(stock2.getPriceNow(), stock2.getLowLimit())) && 2 * Integer.parseInt(stock2.getVolume()) < Integer.parseInt(stock.getVolume()) && !Objects.equals(stock2.getPriceNow(), stock2.getHighLimit())) {
//
//                            String nextGzr2 = getNextGzr(LocalDate.parse(nextGzr, DateTimeFormatter.ofPattern("yyyy-MM-dd")).atStartOfDay());
//
//                            Stock stock3 = stockService.getByCodeAndCalcTimeAndCalcType(stock.getCode(), nextGzr2, 3);
//
//                            double profit = (((stock3.getPriceMax() - stock2.getPriceNow()) / stock2.getPriceNow()) * 100);
//                            log.info("{}入场,{}出场,{},{},买入当天：{},盈利：{},最大盈利：{}", nextGzr,nextGzr2, stock.getCode(), stock.getName(),stock2.getChangePercent(),stock3.getChangePercent(),profit);
//                            break;
//                        }
//                        count++;
//                    }
//                }
//            }
//            calcDate = getNextGzr(LocalDate.parse(calcDate, DateTimeFormatter.ofPattern("yyyy-MM-dd")).atStartOfDay());
//        }
//    }
//
//    public String getNextGzr(LocalDateTime nowLocal) throws ParseException {
//        String calcDate = null;
//        for (int i = 1; i < 10; i++) {
//            nowLocal = nowLocal.plusDays(1);
//            // 定义日期时间格式
//            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
//            // 格式化当前时间
//            String formattedNow = nowLocal.format(formatter);
//            String workingDay = HolidayUtil.isWorkingDay(formattedNow);
//            if("0".equals(workingDay)){
//                calcDate =  formattedNow;
//                break;
//            }
//        }
//        return calcDate;
//    }
//
//}
